
import * as THREE from 'three';
import fragmentShader from './fragmentShader.glsl';
import vertexShader from './vertexShader.glsl';
export default function (opts) {
    const {
        radius = 50,
        color = "#fff",
        speed = 1,
        opacity = 1,
        angle = Math.PI,
        position = {
            x: 0,
            y: 0,
            z: 0
        },
        rotation = {
            x: -Math.PI / 2,
            y: 0,
            z: 0
        }
    } = opts;

    const width = radius * 2;

    const geometry = new THREE.PlaneGeometry(width, width, 1, 1);

    const material = new THREE.ShaderMaterial({
        uniforms: {
            u_radius: {
                value: radius
            },
            u_speed: {
                value: speed
            },
            u_opacity: {
                value: opacity
            },
            u_width: {
                value: angle
            },
            u_color: {
                value: new THREE.Color(color)
            },
            time: {
                value: 0
            }
        },
        transparent: true,
        depthWrite: false,
        side: THREE.DoubleSide,
        vertexShader: vertexShader,
        fragmentShader: fragmentShader
    })

    const mesh = new THREE.Mesh(geometry, material);

    mesh.rotation.set(rotation.x, rotation.y, rotation.z);
    mesh.position.copy(position);

    return mesh
}